class Solution {
public:
    vector<int> sortArrayByParityII(vector<int>& nums) {
        vector<int>arr;
        //4 2 5 7
        //5 2 4 7
        int indexa = 0;//奇数
        int indexb = 0;//偶数
        for (int i = 0; i < nums.size(); i++) {
            if (!(i % 2) || i == 0) {
                while (nums[indexb] % 2) {
                    indexb++;
                }
                arr.push_back(nums[indexb]);
                indexb++;
              
            }
            if (i % 2) {
                while (!(nums[indexa] % 2)) {
                    indexa++;
                }
                arr.push_back(nums[indexa]);
                indexa++;
            }
        }
        return arr;
    }
};